#include "stdint.h"

/*-
 * seg size 64seg*4com
 */



uint8_t *seg_lcd_buff;
uint8_t (*seg_lcd_num_cfg)[9];

void seg_lcd_buff_set(uint8_t * buff)
{
    seg_lcd_buff = buff;
}

void seg_lcd_num_cfg_set(uint8_t (*cfg)[])
{
    seg_lcd_num_cfg = cfg;
}

void seg_lcd_bit_set(uint8_t bit_val)
{

    uint8_t index, offset;
    
    index = bit_val >> 3;
    offset = bit_val & 0x07;
    
    seg_lcd_buff[index] |= 1 << offset;
}

void seg_lcd_bit_clr(uint8_t bit_val)
{
    uint8_t index, offset;
    
    index = bit_val >> 3;
    offset = bit_val & 0x07;
    
    seg_lcd_buff[index] &= ~(1 << offset);
}

void seg_lcd_bit_tog(uint8_t bit_val)
{
    uint8_t index, offset;
    uint8_t msk;
    
    index = bit_val >> 3;
    offset = bit_val & 0x07;
    msk = (1 << offset);
    
    if(seg_lcd_buff[index] & msk)
        seg_lcd_buff[index] &= ~msk;
    else
        seg_lcd_buff[index] |= msk;
}

uint8_t seg_lcd_bit_get(uint8_t bit_val)
{
    uint8_t index, offset;
    uint8_t msk;
    
    index = bit_val >> 3;
    offset = bit_val & 0x07;
    msk = (1 << offset);
    
    if(seg_lcd_buff[index] & msk)
        return 1;
    else
        return 0;
}


void seg_lcd_num_set(uint8_t site, uint8_t val)
{
    uint8_t *src;
    uint8_t bit_val;
    uint8_t cnt;
    uint8_t msk;
    
    src = seg_lcd_num_cfg[site];
    
    for(cnt=0; cnt <= 7 ;cnt++)
    {
        bit_val = src[cnt+1];
        
        if(cnt == 7)
        {
            if(!src[0])
                break;
        }
        
        msk = (1 << (bit_val & 0x07));
        
        if(val & (1 << cnt))
            seg_lcd_buff[bit_val >> 3] |= msk;
        else
            seg_lcd_buff[bit_val >> 3] &= ~msk;
    }
}
